<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderOperateRecord extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('order_operate_record', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('orderId')->default(0)->comment("kf_orders表id");
            $table->unsignedInteger('type')->default(0)->comment("操作类型 1:下单 2:结账 3:反结账");
            $table->text('record')->comment("记录值");
            $table->string('username', 50)->default('')->comment("操作人");
            $table->unsignedInteger('userId')->default(0)->comment("操作人Id");
            $table->unsignedTinyInteger('userType')->default(0)->comment("操作人类型 0 运营后台人员 1 小程序用户");
            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');

            // 索引部分
            $table->index('orderId', 'idx_orderId');

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}order_operate_record` COMMENT = '订单操作记录表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_operate_record');
    }
}
